<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserReceive;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;

class UserReceiveController extends AdminController
{

    public function index(Content $content): Content
    {

        return $content->header('推送消息')
            ->description('当前用户发送的消息会推送给其他用户')
            ->body(
                $this->grid()
            );
    }

    /**
     *
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid(): Grid
    {
        return Grid::make(new UserReceive(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('room_id');
            $grid->column('seq');
            $grid->column('msg_form');
            $grid->column('msg_to');
            $grid->column('delivered');
            $grid->column('create_time')->sortable();;
            $grid->column('update_time')->sortable();
            // 去掉上面的新增功能
            $grid->disableCreateButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserReceive(), function (Show $show) {
            $show->field('id');
            $show->field('room_id');
            $show->field('seq');
            $show->field('msg_form');
            $show->field('msg_to');
            $show->field('delivered');
            $show->field('create_time');
            $show->field('update_time');

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserReceive(), function (Form $form) {
            $form->text('room_id');
            $form->text('seq');
            $form->text('msg_form');
            $form->text('msg_to');
            $form->text('delivered');
            $form->text('create_time');
            $form->text('update_time');

        });
    }
}
